package psi.springapp.mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import model.Party;
import model.User;
import psi.springapp.mvc.service.PartyService;
import psi.springapp.mvc.service.UserService;


@Controller
@RequestMapping(value = "users")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    PartyService partyService;




    @RequestMapping(value = "add", method = RequestMethod.PUT, consumes = "application/json")
    @ResponseStatus(HttpStatus.OK)
    public void put(@RequestBody User user) {
        userService.saveUser(user);
    }

    @RequestMapping(value = "vote/{user_id}:{party_id}", method = RequestMethod.PUT, consumes = "application/json")
    @ResponseStatus(HttpStatus.OK)
    public void voteParty(@PathVariable int user_id, @PathVariable int party_id) {

        User user = userService.getById(user_id);
        Party party = partyService.getById(party_id);
        userService.voteParty(user,party);
    }

    @RequestMapping(value = "deleteAll", method = RequestMethod.DELETE)
    public void deleteAll() {
        userService.deleteAll();
    }
}
